package com.twb.log.controller;

import java.util.Arrays;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotBlank;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.twb.core.base.Result;
import com.twb.core.base.controller.BaseController;
import com.twb.core.base.entity.TwbPageInfo;
import com.twb.core.util.BeanUtils;
import com.twb.core.util.Results;
import com.twb.log.entity.twbLogOperation.TwbLogOperation;
import com.twb.log.entity.twbLogOperation.dto.GetTwbLogOperationByIdDto;
import com.twb.log.entity.twbLogOperation.dto.SearchTwbLogOperationDto;
import com.twb.log.entity.twbLogOperation.vo.SearchTwbLogOperationVo;
import com.twb.log.service.ITwbLogOperationService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

/**
 * @ClassName TwbLogOperationController
 * @Description 系统日志管理
 * @author DSY
 * @date 2018年11月13日 下午5:12:32
 */
@RestController
@RequestMapping("/sys/twbLogOperation")
@Api(value = "TwbLogOperationController", tags = "系统日志管理接口")
public class TwbLogOperationController extends BaseController {

	@Autowired
	ITwbLogOperationService twbLogOperationService;

	/**
	 * @Title  searchTwbLogOperation
	 * @Description 系统日志分页查询
	 * @param vo
	 * @param pageVo
	 * @return
	 * @author DSY
	 * @date 2018年11月13日 下午5:27:53
	 */
	@GetMapping("/search")
	@ApiOperation(value = "系统日志分页查询")
	public Result<TwbPageInfo<SearchTwbLogOperationDto>> searchTwbLogOperation(SearchTwbLogOperationVo vo) {
		TwbPageInfo<SearchTwbLogOperationDto> result = twbLogOperationService.searchTwbLogOperation(vo);
		return Results.successWithData(result);
	}

	/**
	 * @Title  getTwbLogOperationById
	 * @Description 根据ID获取系统日志详情
	 * @param id
	 * @return
	 * @author DSY
	 * @date 2018年11月14日 下午3:48:06
	 */
	@GetMapping("/getById")
	@ApiOperation(value = "根据ID获取系统日志详情")
	public Result<GetTwbLogOperationByIdDto> getTwbLogOperationById(
			@NotBlank @RequestParam @ApiParam(value = "序号", name = "id", required = true) String id) {
		TwbLogOperation twbLogOperation = twbLogOperationService.getById(id);
		GetTwbLogOperationByIdDto LogOperationDto = new GetTwbLogOperationByIdDto();
		BeanUtils.copyNotNullProperties(twbLogOperation, LogOperationDto);
		return Results.successWithData(LogOperationDto);
	}

	/**
	 * @Title  deleteTwbLogOperationById
	 * @Description 删除系统日志信息
	 * @param id
	 * @return
	 * @author DSY
	 * @date 2018年11月14日 下午4:21:46
	 */
	@PostMapping("/deleteById")
	@ApiOperation(value = "删除系统日志信息")
	public Result<String> deleteTwbLogOperationById(
			@NotBlank @RequestParam @ApiParam(value = "序号", name = "id", required = true) String id) {
		boolean result = twbLogOperationService.removeById(id);
		if (result) {
			return Results.success("删除成功");
		} else {
			return Results.failure("删除失败");
		}
	}

	/**
	 * @Title  batchDeleteTwbLogOperationByIds
	 * @Description 批量删除系统日志
	 * @param ids
	 * @return
	 * @author DSY
	 * @date 2018年11月27日 下午12:06:15
	 */
	@PostMapping("/batchDeleteByIds")
	@ApiOperation(value = "批量删除系统日志信息")
	public Result<String> batchDeleteTwbLogOperationByIds(
			@NotBlank @RequestParam @ApiParam(value = "序号", name = "ids", required = true) String ids) {
		boolean result = twbLogOperationService.removeByIds(Arrays.asList(ids.split(",")));
		if (result) {
			return Results.success("删除成功");
		} else {
			return Results.failure("删除失败");
		}
	}
	
	/**
	 * @Title exportExcel
	 * @Description 导出Excel
	 * @param vo
	 * @param response
	 * @throws Exception
	 * @AuthorOriginally 杜顺亚
	 * @date 2022年8月22日 下午6:35:35
	 */
	@PostMapping("/exportExcel")
	@ApiOperation(value="导出excel")
	public void exportExcel(@RequestBody SearchTwbLogOperationVo vo, HttpServletResponse response) throws Exception {
		twbLogOperationService.exportExcel(vo, response);
	}
}
